package com.jcl.recruit.console.corp.logic;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jcl.core.common.page.PageResult;
import com.jcl.core.utils.CollectionUtils;
import com.jcl.recruit.console.ConsoleCorpDao;
import com.jcl.recruit.console.model.ConsoleCorpInfo;
import com.jcl.recruit.console.vo.ConsoleCorpPageCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.springframework.beans.support.PagedListHolder.DEFAULT_PAGE_SIZE;

/**
 * @ClassName ConsoleCorpLogic
 * @Author yyliu
 * @Date 2018/12/25 16:22
 * @Version 1.0
 **/
@Component
public class ConsoleCorpLogic {

    @Autowired
    private ConsoleCorpDao consoleCorpDao;

    public PageResult pageResult(ConsoleCorpPageCondition condition,
                                 Integer curPage,
                                 Integer rowSize) {
        curPage = null == curPage ? 1 : rowSize;
        rowSize = null == rowSize ? DEFAULT_PAGE_SIZE : rowSize;
        PageHelper.startPage(curPage, rowSize);
        List<ConsoleCorpInfo> list = consoleCorpDao.pageList(condition);
        PageInfo info = new PageInfo(list);
        return new PageResult(curPage, rowSize, info.getTotal(), info.getList());


    }

    public List<Map<String, Object>> selectList() {
        List<Map<String, Object>> dataList = new ArrayList<>();
        List<ConsoleCorpInfo> list = consoleCorpDao.findList();
        if (CollectionUtils.isNotEmpty(list)) {
            for (ConsoleCorpInfo corpInfo : list) {
                Map<String, Object> map = new HashMap<>();
                map.put("name", corpInfo.getFullName());
                map.put("code", corpInfo.getCode());
                dataList.add(map);
            }
        }
        return dataList;
    }


}
